package org.hot100_1;

public class leetcode10 {

    //前缀和
    public int subarraySum(int[] nums, int k){

        int n = nums.length;
        int [] preSums = new int[n+1];
        preSums[0]=0;

        for (int i = 0; i < n; i++) {
            preSums[i+1]=preSums[i]+nums[i];
        }
        int res =0;
        for (int left = 0; left < n; left++) {
            for (int right = left; right < n; right++) {
                if (preSums[right+1]-preSums[left]==k){
                    res++;
                }
            }
        }

        return res;
    }
}
